package com.liqin.nothing.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.liqin.nothing.entity.Person;
import com.liqin.nothing.result.R;
import com.liqin.nothing.result.Response;
import com.liqin.nothing.service.PersonService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author gonghl
 * @since 2024-05-28
 */
@RestController
@RequestMapping("/person")
@RequiredArgsConstructor
public class PersonController {

    private final PersonService personService;

    @GetMapping("/getPerson")
    public List<Person> getPerson() {
        return personService.getPerson();
    }

    @GetMapping("/insertBatch")
    public void insertBatch() {
        List<Person> list = new ArrayList<>();
        for (int i = 1; i <= 5; i++) {
            list.add(new Person().setName("lisa" + i).setAge(11).setSex("女"));
        }
        personService.saveBatch(list);
    }

    @GetMapping("/updatePerson/{id}")
    public boolean getAllPerson(@PathVariable Integer id) {
        return personService.updateById(new Person().setId(id).setName("joker"));
    }


    @GetMapping("/getPersonName")
    public List<Object> getPersonName() {
        return personService.getPersonName();
    }

    @GetMapping("/page")
    public Response<Page<Person>> pagePerson(Page<Person> page, Person person) {
        return R.success(personService.page(page, person));
    }

}
